﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ThesisSystem.Models;
using ThesisSystem.DAL;

namespace ThesisSystem.Controllers
{ 
    public class ProfessionController : Controller
    {
        private ThesisSystemEntities db = new ThesisSystemEntities();

        //
        // GET: /Profession/

        public ViewResult Index()
        {
            return View(db.Professions.Include(p=>p.Department).ToList());
        }

        //
        // GET: /Profession/Details/5

        public ViewResult Details(int id)
        {
            Profession profession = db.Professions.Find(id);
            return View(profession);
        }

        //
        // GET: /Profession/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Profession/Create

        [HttpPost]
        public ActionResult Create(Profession profession)
        {
            if (ModelState.IsValid)
            {
                db.Professions.Add(profession);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(profession);
        }
        
        //
        // GET: /Profession/Edit/5
 
        public ActionResult Edit(int id)
        {
            Profession profession = db.Professions.Find(id);
            return View(profession);
        }

        //
        // POST: /Profession/Edit/5

        [HttpPost]
        public ActionResult Edit(Profession profession)
        {
            if (ModelState.IsValid)
            {
                db.Entry(profession).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(profession);
        }

        //
        // GET: /Profession/Delete/5
 
        public ActionResult Delete(int id)
        {
            Profession profession = db.Professions.Find(id);
            return View(profession);
        }

        //
        // POST: /Profession/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Profession profession = db.Professions.Find(id);
            db.Professions.Remove(profession);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}